//
//  MainTableViewController.m
//  AIM
//
//  Created by user10 on 2017/5/15.
//  Copyright © 2017年 user10. All rights reserved.
//

#import "MainTableViewController.h"
#import "Goods.h"

@interface MainTableViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    NSArray *_persons;
}
@property (assign,nonatomic)BOOL transiting;
@end

@implementation MainTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    Goods *p0 = [[Goods alloc] init];
    p0.name = @"路飞";
    p0.headStr = @"person0";
    p0.speechText = @"我要当海贼王！";
    
    Goods *p1 = [[Goods alloc] init];
    p1.name = @"卓洛";
    p1.headStr = @"person1";
    p1.speechText = @"受尽磨难而不折，此乃修罗之道！";
    
    Goods *p2 = [[Goods alloc] init];
    p2.name = @"罗宾";
    p2.headStr = @"person2";
    p2.speechText = @"我要活下去，把我带向大海吧！";
    
    Goods *p3 = [[Goods alloc] init];
    p3.name = @"娜美";
    p3.headStr = @"person3";
    p3.speechText = @"帮帮我，路飞！";
    
    _persons = [NSArray arrayWithObjects:p0,p1,p2,p3, nil];
}

- (void)viewWillAppear:(BOOL)animated {
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    [super viewWillDisappear:animated];
}
- (IBAction)searchBtn:(UIButton *)sender {
    
    NSLog(@"搜索");
}
- (IBAction)logOutBtn:(UIButton *)sender {
    NSLog(@"退出");
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleIdentify = @"SimpleIdentify";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleIdentify];
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"mainTableViewCell" owner:self options:nil];
    if ([nib count]>0)
    {
        self.customCell = [nib objectAtIndex:0];
        cell = self.customCell;
    }
    //获取数据源中_person数组中的元素，对应每一个cell
    Goods *person = [_persons objectAtIndex:indexPath.row];
    //通过tag值来获取UIImageView和UILabel
//    UIImageView *headImageView = (UIImageView *)[cell.contentView viewWithTag:0];
    UILabel *nameLabel = (UILabel *)[cell.contentView viewWithTag:1];
    UILabel *textLabel = (UILabel *)[cell.contentView viewWithTag:2];
//    headImageView.image = [UIImage imageNamed:person.headStr];
    nameLabel.text = person.name;
    textLabel.text = person.speechText;
    
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
    
}
@end
